class Solution(object):
    def containsNearbyDuplicate(self, nums, k):
        """
        :type nums: List[int]
        :type k: int
        :rtype: bool
        """
        hash_dict = {}
        for index, num in enumerate(nums):
            if num in hash_dict and (index - hash_dict[num]) <= k:
                return True
            hash_dict[num] = index
        return False
        
if __name__ == '__main__':
    nums = [1,2,3,1,2,3]
    k = 2
    print(Solution().containsNearbyDuplicate(nums, k))